// 12/04/2009 Dennis
class Track
{
  String name;
  Artist artist;
  Album album;
  HashMap users;
  ArrayList allUsers;
  
  // 12/04/2009 Dennis
  public Track(String name, Artist artist, Album album)
  {
    this.name = name;
    this.artist = artist;
    this.album = album;
    users = new HashMap();
    allUsers = new ArrayList();
  }
  
  // 26/04/2009 Dennis, Bagdat, David
  public int getPopularity(String userName, long start, long end)
  {
    if(userName == null)
    {
      if(start == 0 && end == 0)
        return allUsers.size();
      else
      {
        int result = 0;
        for(int i = 0; i < allUsers.size(); i++)
        {
          Long time = (Long)allUsers.get(i);
          if(time >= start && time <= end)
            result++;
          if(time > end)
            break;
        }
        return result;
      }
    }
    else
    {
      if(!users.containsKey(userName))
        return 0;
      ArrayList timeList = (ArrayList)users.get(userName);
      if(start == 0 && end == 0)
        return timeList.size();
      else
      {
        int result = 0;
        for(int i = 0; i < timeList.size(); i++)
        {
          Long time = (Long)timeList.get(i);
          if(time >= start && time <= end)
            result++;
          if(time > end)
            break;
        }
        return result;
      }
    }
  }
  
  // 26/04/2009 Dennis, Bagdat
  public void addPlayed(String userName, long time)
  {
    ArrayList timeList;
    if(users.containsKey(userName))
    {
      timeList = (ArrayList)users.get(userName);
    }
    else
    {
      timeList = new ArrayList();
      users.put(userName, timeList);
    }
    timeList.add(time);
    allUsers.add(time);
  }
}
